<div class="mail-right-block grid_6">
<div class="browse-tl">
		<div class="browse-tr">
				<div class="browse-top"> </div>
		</div>
	</div>
		<div class="browse-left shad-bg-lft clearfix">
			<div class="browse-right shad-bg-rgt">
				<div class="shad-bg discover-menu  discover-menu1 clearfix">
	<h3 class="mail-head"><?php echo __l('Messages');?> </h3>

    <?php echo $this->element('message_message-left_sidebar', array('config' => 'sec')); ?>
    </div>
	</div>
						</div>
						<div class="browse-bl">
						<div class="browse-br">
						<div class="browse-bot"></div>
							</div>
						</div>
</div>
<div class="messages message-side2 grid_18 index">
<div class="l-curve-top">							
							<div class="r-curve-top">
								<div class="top-bg"></div>
							</div>
						</div>
						<div class="shad-bg-lft clearfix">
							<div class="shad-bg-rgt">
								<div class="shad-bg">
								<div class="main-section">
<h2 class="title"><?php echo __l('Compose') ?></h2>
<?php echo $this->Form->create('Message', array('action' => 'compose', 'class' => 'compose normal', 'enctype' => 'multipart/form-data')); ?>
<?php
	if (!empty($all_parents)) :
    	foreach($all_parents as $parent_message) : ?>
			<div class="clearfix admin-compose">
            <h1>
               <?php
                 if($parent_message['OtherUser']['id'] == $this->Auth->user('id'))
                 {
                   echo __l('Me');
                 }
                 else
                 {
                  echo $this->Html->cText($parent_message['OtherUser']['username']); 
                 }
              ?>
            </h1>
			<p>
              <?php
                echo __l('to ');
                if($parent_message['User']['id'] == $this->Auth->user('id'))
                 {
                   echo __l('Me');
                 }
                 else
                 {
                  echo $this->Html->cText($parent_message['User']['username']);
                 }
             ?>
            </p>
            <p><?php echo $this->Html->cText($parent_message['MessageContent']['message']); ?></p></div>
            <?php
        endforeach;
    endif;
?>
<div class="compose-block clearfix">
<div class="message-block-right submit-block clearfix delete-block" >
 <?php echo $this->Form->submit(__l('Send'), array('class' => 'js-without-subject', 'name' => 'data[Message][send]')); ?>
 <?php echo $this->Form->submit(__l('Save'), array('value' => 'draft', 'name' => 'data[Message][save]')); ?>
 <div class="cancel-block">
 <?php echo $this->Html->link(__l('Discard') , array('controller' => 'messages', 'action' => 'inbox') , array('class' => 'js-compose-delete compose-delete','title' => __l('Discard')) , null, false); ?>
 </div>
  <div class="cancel-block">
 <?php echo $this->Html->link(__l('Cancel'), array('controller' => 'messages', 'action' => 'inbox') , array('title' => __l('Cancel'))); ?>
 </div></div>
 </div>
 <div class="compose-box">
	<fieldset>
	    <div class="clearfix input">
 
    <span class="message-title grid_left alpha">
        <?php 	echo __l('From'); ?>
    </span>
    <span class="grid_left">
             <?php echo $this->Html->link($this->Html->cText($this->Auth->user('username')), array('controller'=> 'users', 'action' => 'view', $this->Auth->user('username')), array('title' => $this->Html->cText($this->Auth->user('username'),false),'escape' => false));
             ?>
     </span>
    </div>
	<?php if(!empty($this->request->data['Message']['to_username'])): ?>
	<div class="clearfix input">
	     <span class="grid_left message-title">
		 <?php 	echo __l('To'); ?>
		 </span>

		  <span class="grid_left">
	       	<?php echo !empty($this->request->data['Message']['to_username']) ? $this->Html->link($this->Html->cText($this->request->data['Message']['to_username']), array('controller'=> 'users', 'action' => 'view', $this->request->data['Message']['to_username']), array('title' => $this->Html->cText($this->request->data['Message']['to_username'],false),'escape' => false)) : ''; ?>
        </span>
</div>
<?php endif; ?>
    <?php if (!empty($this->request->data['Message']['project_name'])): ?>
    <div class="clearfix input">
		<span class="grid_left message-title">
			<?php echo __l('Project');  ?>
		</span>
		<span class="grid_left">
		<?php echo $this->Html->link($this->Html->cText($this->request->data['Message']['project_name']), array('controller' => 'projects', 'action' => 'view',  $this->request->data['Message']['project_slug']), array('title' => $this->Html->cText($this->request->data['Message']['project_name'],false),'escape' => false));?>
		</span>
    </div>
 <?php	endif;  ?>
			<?php

			if(!empty($this->request->data['Message']['to_username'])):
						echo $this->Form->input('to_username', array('type' => 'hidden', 'id' => 'message-to'));
						echo $this->Form->input('to', array('type' => 'hidden', 'id' => 'message-to-name', 'value' => $this->request->data['Message']['to_username']));
			else:
			?>
               <div class="mapblock-info"  style="min-height:0">
            <?php
                            echo $this->Form->autocomplete('Message.to', array('label' => __l('To'), 'type' => 'text', 'id' => 'MessageUsername', 'acFieldKey' => 'User.id', 'acFields' => array('User.username'), 'acSearchFieldNames' => array('User.username'), 'maxlength' => '255'));
            ?>
                <div class="autocompleteblock"></div>
            </div>
           <?PHP
				//echo $this->Form->autocomplete('to', array('type' => 'text', 'id' => 'message-to', 'acFieldKey' => 'User.id', 'acFields' => array('User.username'), 'acSearchFieldNames' => array('User.username'), 'maxlength' => '255'));
			endif;
				echo $this->Form->input('parent_message_id', array('type' => 'hidden'));
				echo $this->Form->input('type', array('type' => 'hidden'));
			?>
			<?php
				echo $this->Form->input('subject', array('id' => 'MessSubject', 'maxlength' => '100', 'label'=>__l('Subject')));
            ?>

            <div class="atachment">
			<?php echo $this->Form->input('Attachment.filename. ', array('type' => 'file', 'label' => '','size' => '33', 'class' => 'multi file attachment browse-field')); ?>
			</div>
			<p><?php echo $this->Html->link(__l('Add more attachment'),array('#'),array('class'=>'js-attachmant add','title' => __l('Add more attachment')));?></p>
			<div class="js-attachment-list">
				<?php 
					if(!empty($parent_message['MessageContent']['Attachment'])) {
				?>
						 <ol class="clearfix attachment">
				<?php
						foreach($parent_message['MessageContent']['Attachment'] as $attachment) {
				?>
						<li>
							<div class="js-old-attachmant-div-<?php echo $attachment['id']; ?>">
							<?php 
								echo $attachment['filename'];
								echo $this->Form->input('OldAttachment.'.$attachment['id'].'.id', array('type' => 'hidden'));
								echo $this->Html->link(__l('Remove attachment'), array('#'), array('class'=>'delete js-old-attachmant {"id" : "'.$attachment['id'].'"}','title' => __l('Remove attachment')));
							?>
							</div>
						</li>
				<?php
						}
				?>
						</ol>
				<?php
					}
				?>
			</div>

			<?php
			if(!empty($this->request->params['named']['project_id'])):
				echo $this->Form->input('project_id', array('type' => 'hidden','value'=>$this->request->params['named']['project_id'])); 
			endif;
			echo $this->Form->input('message', array('type' => 'textarea', 'label' => 'Comments'));
			 echo $this->Form->input('message_content_id', array('type' => 'hidden')); ?>
	</fieldset>
</div>
<div class="compose-block clearfix">
<div class="message-block-right submit-block clearfix delete-block" >
	<?php echo $this->Form->submit(__l('Send'), array('class' => 'js-without-subject')); ?>
	<?php echo $this->Form->submit(__l('Save'), array('value' => 'draft', 'name' => 'data[Message][save]')); ?>
	<div class="cancel-block">
	<?php echo $this->Html->link(__l('Discard') , array('controller' => 'messages', 'action' => 'inbox') , array('class' => 'js-compose-delete compose-delete','title' => __l('Discard')) , null, false); ?>
	</div>
		<div class="cancel-block">
    <?php echo $this->Html->link(__l('Cancel'), array('controller' => 'messages', 'action' => 'inbox') , array('title' => __l('Cancel'))); ?>
</div></div>
</div>
<?php echo $this->Form->end(); ?>
 </div>
	</div>
							</div>
						</div>
						<div class="l-curve-bot">							
							<div class="r-curve-bot">
								<div class="bot-bg"></div>
							</div>
						</div>
</div>
